

use "$data/survey1_clean.dta", clear


global control male age_* log_inc log_inc_sq highschool college working student democrat republican 


*** Correlation with perceptions ***
   
gen high_mortalityperc = perceived_mortality>3.4 if perceived_mortality!=.
gen high_contagiousnesssperc = perceived_contagion>2 if perceived_contagion!=.

loc experiments "z_impact_1 z_impact_2 z_worry_corona_econ z_worry_perecon"
		   
			  
			  
preserve 

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""

global output_coeff " "
global output_se " "
global output_name " "

foreach choice in `experiments' {

/* Statistics */

	
 reg `choice' high_mortalityperc  high_contagiousnesssperc , vce(r)
 
 if "`choice'" == "z_worry_corona_econ" |  "`choice'" == "z_worry_perecon" {

 	global `choice'_coeff =_b[high_mortalityperc]
	global `choice'_se =_se[high_mortalityperc]
	global output_name "$output_name `choice' "
	global output_coeff "$output_coeff $`choice'_coeff "
	global output_se "$output_se $`choice'_se "
	
		
	global `choice'_coeff =_b[high_contagiousnesssperc]
	global `choice'_se =_se[high_contagiousnesssperc]
	global output_name "$output_name `choice' "
	global output_coeff "$output_coeff $`choice'_coeff "
	global output_se "$output_se $`choice'_se" 
	}

	estadd loc thisstat9 = string(`e(r2)', "%9.2f"): col`colnum'
 
    sigstar high_mortalityperc, prec(4)
    estadd loc thisstat3 = "`r(bstar)'": col`colnum'
    estadd loc thisstat4 = "`r(sestar)'": col`colnum'
	

    sigstar high_contagiousnesssperc, prec(4)
    estadd loc thisstat6 = "`r(bstar)'": col`colnum'
    estadd loc thisstat7 = "`r(sestar)'": col`colnum'		


	

	** With controls **
	
 xi:  reg `choice' high_mortalityperc  high_contagiousnesssperc $control, vce(r)
 	
	estadd loc thisstat20 = string(`e(r2)', "%9.2f"): col`colnum'
 
    sigstar high_mortalityperc, prec(4)
    estadd loc thisstat14 = "`r(bstar)'": col`colnum'
    estadd loc thisstat15 = "`r(sestar)'": col`colnum'
	
	lincom high_mortalityperc

    sigstar high_contagiousnesssperc, prec(4)
    estadd loc thisstat17 = "`r(bstar)'": col`colnum'
    estadd loc thisstat18 = "`r(sestar)'": col`colnum'			

	qui sum `choice'  
	estadd loc thisstat21 =  r(N): col`colnum'
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

	} 
	

loc rowlabels " "{\bf Panel A: No control variables}"  " " "Overestimate mortality" " "  " " "Overestimate contagiousness" " " " " "\midrule R$^2$" "\midrule" " " "{\bf Panel B: Including control variables}"  " " "Overestimate mortality" " "  " " "Overestimate contagiousness" " " " "  "\midrule R$^2$" " Number of Observations ""
loc rowstats ""

forval i = 1/21 {
    loc rowstats "`rowstats' thisstat`i'"
}

	
esttab * using "$tables/experiment_correlations_combined.tex", replace cells(none) booktabs nonotes compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
 mtitle("World" "US" "US Economy" "Pers. Economic Sit."  ) ///
mgroups("Predicted impact on (standardized)" "Worry about (standardized)" ,  pattern(1 0  1 0   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

clear 

di $output_coeff

set obs 6
gen name_var = " "
gen coeff =" "
local l =1
foreach x in $output_name {
replace name_var = "`x'" in `l'
local ++l
}

local l =1
foreach x in $output_coeff {
replace coeff = "`x'" in `l'
local ++l
}

gen se =""
local l =1
foreach x in $output_se {
replace se = "`x'" in `l'
local ++l
}
destring se coeff, replace

gen uci = coeff+1.96*se
gen lci =coeff-1.96*se



export delimited using "$tables/tables_raw/tablescornew.csv", replace

